{include file="base/header"}
        <div class="layui-card">
            <div class="layui-card-body">
                <form class="layui-form" action="">
                    <div class="layui-form-item">
                        <div class="layui-form-item layui-inline">
                            <label class="layui-form-label">用户名</label>
                            <div class="layui-input-inline">
                                <input type="text" name="username" placeholder="" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item layui-inline">
                            <label class="layui-form-label">姓名</label>
                            <div class="layui-input-inline">
                                <input type="text" name="reaname" placeholder="" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item layui-inline">
                            <label class="layui-form-label">电话</label>
                            <div class="layui-input-inline">
                                <input type="text" name="mobile" placeholder="" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item layui-inline">
                            <button class="pear-btn pear-btn-md pear-btn-primary" lay-submit lay-filter="user-query">
                                <i class="layui-icon layui-icon-search"></i>
                                查询
                            </button>
                            <button type="reset" class="pear-btn pear-btn-md">
                                <i class="layui-icon layui-icon-refresh"></i>
                                重置
                            </button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
        
        <div class="layui-card">
            <div class="layui-card-body">
                <table id="tableId" lay-filter="user-table"></table>
            </div>
        </div>
            <script type="text/html" id="user-toolbar">
                <button class="pear-btn pear-btn-primary pear-btn-md" lay-event="add">
                    <i class="layui-icon layui-icon-add-1"></i>
                    新增管理员
                </button>
            </script>
        <script type="text/html" id="user-img">
            <img src="/static/efile/auserimg/{{d.img}}" class="layui-nav-img">
        </script>
        
        <script type="text/html" id="user-rolename">
            {{#if (d.role_id == 1) { }}
                <span class="layui-badge layui-bg-black">{{d.rolename}}</span>
            {{# }else{ }}
                <span class="layui-badge layui-bg-blue">{{d.rolename}}</span>
            {{# } }}
        </script>
        <script type="text/html" id="user-status">
            {{#if (d.id != 1) { }}
            	<input type="checkbox" name="status" value="{{d.id}}" lay-skin="switch" lay-text="开启|冻结" lay-filter="user-status-set" {{ !d.status ? 'checked' : '' }} />
                {{# }else{ }}
                <input type="checkbox" name="status" value="{{d.id}}" lay-skin="switch" lay-text="开启|冻结" checked disabled />
                {{#} }}
        </script>
        <script type="text/html" id="user-set">
                    {{#if (d.id != 1) { }}
                        <button class="pear-btn pear-btn-primary pear-btn-xs" lay-event="edit">编辑</button>
                    {{#} }}
                    {{#if (d.id == 1) { }}
                        {if $Request.session.lt_auser.id == 1}
                         <button class="pear-btn pear-btn-primary pear-btn-xs" lay-event="edit">编辑</button>
                        {/if}
                    {{#} }}
        			
                    {{#if (d.id != 1) { }}
        		    <button class="pear-btn pear-btn-danger pear-btn-xs" lay-event="delete">删除</button>
                    {{#} }}
        </script>
        <script>
			layui.use(['table', 'form', 'jquery','common'], function() {
				let table = layui.table;
				let form = layui.form;
				let $ = layui.jquery;
				let common = layui.common;
                let cols = [
                    [{
                        title: 'ID',
                        field: 'id',
                        align: 'center',
                        width: 50
                    },
                    {
                            title: '头像',
                            field: 'img',
                            align: 'center',
                            width: 100,
                            templet: '#user-img'
                        },
                    {
                        title: '账号',
                        field: 'username',
                        align: 'left',
                        width: 200
                    },
                    {
                            title: '昵称',
                            field: 'nickname',
                            align: 'center'
                        },
                    {
                        title: '姓名',
                        field: 'reaname',
                        align: 'center'
                    },
                    {
                        title: '电话',
                        field: 'mobile',
                        align: 'center'
                    },
                    {
                            title: '角色',
                            field: 'rolename',
                            align: 'center',
                             templet: '#user-rolename'
                        },
                    {
                        title: '状态',
                        field: 'status',
                        align: 'center',
                        templet: '#user-status'
                    },
                    {
                        title: '添加',
                        field: 'addtime',
                        align: 'center'
                    },
                    {
                        title: '操作',
                        toolbar: '#user-set',
                        align: 'left',
                        width: 150
                    }
                    ]
                ];
                table.render({
                    elem: '#tableId',
                    url: "{:url('admin/auser')}",
                    page: true,
                    cols: cols,
                    skin: 'line',
                    toolbar: '#user-toolbar',
                    defaultToolbar: [{
                        title: '刷新',
                        layEvent: 'refresh',
                        icon: 'layui-icon-refresh',
                    }, 'filter',  'exports']
                });
                form.on('switch(user-status-set)', function (obj) {
                    console.log(obj);
                    var id= this.value;
                    var status= obj.elem.checked ? 0 :1 ;
                    var str= !status ? "已开启，可正常登录" : "已冻结，不可登录";
                    postData("{:url('admin/setUserStatus')}",{ id,status }).then(function(res){
                        if(res.code!=200){
                            layer.alert(res.message,{title:"提示"});
                            return;
                        }
                        layer.tips(str, obj.othis);
                    });

                });
                table.on('tool(user-table)', function (obj) {
                    if (obj.event === 'edit') {
                 
                        window.edit(obj.data);
                    }
                    if (obj.event === 'delete') {

                        window.delete(obj);
                    }
                });
                table.on('toolbar(user-table)', function (obj) {
                    if (obj.event === 'add') {

                        window.add();
                    }else if (obj.event === 'refresh') {
						window.refresh();
					}
                });
                window.refresh = function(param) {
					table.reload('tableId');
				}

                window.add = function () {

                    layer.open({
                        type: 2,
                        title: '新增管理员',
                        shade: 0.1,
                        area: ['500px', '600px'],
                        content: "{:url('admin/auseredit')}?id=0"
                    });
                }
                window.edit = function (data) {
                         
                    layer.open({
                        type: 2,
                        title: '修改管理员->'+ data.username,
                        shade: 0.1,
                        area: ['500px', '650px'],
                        content: "{:url('admin/auseredit')}?id="+data.id
                    });
                }
                window.delete = function (obj) {
                    var id=obj.data.id;
                    layer.confirm('确定要删除该用户->'+obj.data.username, {
                        icon: 3,
                        title: '提示'
                    }, function (index) {
                        layer.close(index);
                        loading=layer.load();
                        postData("{:url('admin/auserDelete')}",{id:obj.data.id}).then(function(res){
                           layer.close(loading);
                     
                            if(res.code==200){
                                layer.msg(res.message, {
                                    icon: 1,
                                    time: 1000
                                }, function () {
                                    obj.del();
                                });
                                return;
                            }
                            layer.msg(res.message, {
                                icon: 2,
                                time: 1000
                            });
                        });
                    });
                    
                }
   

                form.on('submit(user-query)', function (data) {
                    table.reload('tableId', {
                        page: {curr: 1 },
                        where: data.field
                    })
                    return false;
                });

			})
		</script>
        </script>
{include file="base/footer"}